package com.wall.haven.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ImageUtil {

    public static final String MATCH_ID_REGEX = "(?:wallhaven-)?([a-zA-Z0-9]+)\\.(?:jpg|png)";

    public static final Pattern pattern = Pattern.compile(MATCH_ID_REGEX);

    /**
     * 获取图片id
     * @param url 图片URL
     * @return
     */
    public static String getImageId(String url){
        Matcher matcher = pattern.matcher(url);
        if (matcher.find()) {
            return matcher.group(1);
        }else{
            return null;
        }
    }
}
